package com.catmiw.csdn;

import java.io.File;
import java.io.IOException;
import java.util.Iterator;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;

import com.catmiw.wyz.util.DigestUtils;
import com.catmiw.wyz.util.NetUtils;

public class JSoupTest {

	/**
	 * @param args
	 *D:\信安工作\2012\08开发规范\chm\html
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		File input = new File("D:\\信安工作\\2012\\08开发规范\\chm\\html\\Untitled-2.html");
		Document doc = Jsoup.parse(input, "UTF-8", "http://example.com/");

		
		Elements masthead = doc.select("div.collins_en_cn");
		Iterator<Element> iterator=masthead.iterator();
		while(iterator.hasNext()){
			Element ele=iterator.next();
			Element span=ele.select("span.num").first();
//			System.out.print(span.text()+"|");
			span=ele.select("span.st").first();
//			System.out.print(span.ownText()+"|");
			span=ele.select("span.text_blue").first();
//			System.out.print(span.ownText()+"|");
			Element div=ele.select("div.caption").first();
			String t=div.html();
			t=t.replace("<b>", "").replace("</b>", "");
			div.html(t);
			System.out.println(div.ownText());
		}
		
		Elements prons=doc.select("div.group_prons > div.group_inf >ul >li ");
		
		if (prons!=null){
			for (int i=0;i<prons.size();i++){
				Element e=prons.get(i);
				System.out.println(prons.get(i).ownText());
				Elements ee=e.select("a");
				if (ee!=null){
					for (int j=0;j<ee.size();j++){
						System.out.println(ee.get(j).ownText());
					}
				}
			}
		}
		//\"http://res.iciba.com/resource/amp3/0/0/cc/59/cc5985ab3406f600b03a786c516fb09a.mp3\
		System.out.println("--------------");
		Elements mp3s=doc.select("a[onmouseover*=resource]");
		if (mp3s!=null){
			for (int i=0;i<mp3s.size();i++){
				Element e=mp3s.get(i);
				System.out.println(e.attr("onmouseover"));
			}
		}
		String md=DigestUtils.md5Hex("test");
		System.out.println(md);
	}

}
